This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Dec 8, 2012, 2:46 PM
35 Posts
topic has been resolvedResolved

Add text var into zipoutstream file

  • Category: Other
  • Platform: Windows
  • Release: 8.5.3
  • Role: End user,Developer,Administrator
  • Tags:
  • Replies: 5
Hi Forum,
 
I'm looking for a way to create a HTML file from the content of a HTML computed field value. Thx to the forum I was able to create a file and directly download it to the browser. (http://www.wissel.net/blog/d6plinks/shwl-7mgfbn) 
 
But because I have multiple files, I'm only able to download 1 file, my idea is to create the files into a rich text field contained into the document and to create a File Download control with a databinding to that rich text field and let the user download the files one by one. 
 
Can someone help me with some code / hints to create a HTML file from a computed field value (probably using outStream) and to add / save that file into a document rich text field? (where other files could already by present)
 
Maybe the next code could be a good start: => But this will write the content into a rich text, I need to create a file of the content before adding it into the rich text field...
 
Source:  http://www.bleedyellow.com/blogs/martin/entry/save_a_richtext_field_from_a_xpage_to_a_document?lang=fr_fr
 
var doc = configuratieformulieren.getDocumentByKey("ConfiguratieIVNL", true);
if(doc == null){
    return;
}else{    
    var titel = getComponent("inputTextIBPTitelIVNL").getValue();
    doc.replaceItemValue("IBPTitel",titel);    
    var inhoud = getComponent("inputRichTextIBPInhoudIVNL").getValue();
    if (inhoud != null){ 
    var contentType = doc.getMIMEEntity("IBPInhoud").getContentType();
    var encoding = doc.getMIMEEntity("IBPInhoud").getEncoding();
    var str = session.createStream();
    inhoud.toString();
    str.writeText(inhoud.toString());
    doc.getMIMEEntity("IBPInhoud").setContentFromText(str, contentType, encoding);    
    }

    doc.save(true, true);
}
sessionScope.put("FormulierIVNLInfoBeschPG","Lezen"); 
 
Thx in advance for your help. 
 
Have a nice week-end. 
 
Chris 
Dec 8, 2012, 3:54 PM
35 Posts
Re: Xpage create HTML file into document Rich Text field
 Hi Forum,
 
I'm back... in the meantime I found something interesting: 
 
http://openntf.org/XSnippets.nsf/snippet.xsp?id=download-all-attachments
 
var downloadDocument:NotesDocument = database.getDocumentByUNID(context.getUrl().getParameter("documentUNID"));
var attachments:java.util.Vector = session.evaluate("@AttachmentNames", downloadDocument);
// If there are no attachments then STOP!
if (attachments == null || (attachments.size() == 1 && attachments.get(0).toString().trim().equals(""))) {
  this.setRendered(true); // Show the XPage
  return;
}
 
var externalContext:javax.faces.context.ExternalContext = facesContext.getExternalContext();
var response:javax.servlet.http.HttpServletResponse = externalContext.getResponse();
 
// Get the name of the zip file to be shown in download dialog box
var zipFileName = context.getUrl().getParameter("zipFileName");
if (zipFileName == null || zipFileName.equals("")) {
  zipFileName = "AllAttachments.zip";
} else if (!zipFileName.toLowerCase().endsWith(".zip")) {
  zipFileName = zipFileName + ".zip";
}
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", -1);
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=" + zipFileName);
 
var outStream:java.io.OutputStream = response.getOutputStream();
var zipOutStream:java.util.zip.ZipOutputStream = new java.util.zip.ZipOutputStream(outStream);
var embeddedObj:NotesEmbeddedObject = null;
var bufferInStream:java.io.BufferedInputStream = null;
 
// Loop through all the attachments
for (var i = 0; i < attachments.size(); i++) {
  embeddedObj = downloadDocument.getAttachment(attachments.get(i).toString());
  if (embeddedObj != null) {
    bufferInStream = new java.io.BufferedInputStream(embeddedObj.getInputStream());
    var bufferLength = bufferInStream.available();
    var data = new byte[bufferLength];
    bufferInStream.read(data, 0, bufferLength); // Read the attachment data
    var entry:java.util.zip.ZipEntry = new java.util.zip.ZipEntry(embeddedObj.getName());
    zipOutStream.putNextEntry(entry);
    zipOutStream.write(data); // Write attachment into Zip
    bufferInStream.close();
    embeddedObj.recycle();
  }
}
 
 // I tried to add some code here to create the last file using a text stream and to add it to the zip, file htmlfile.html is created inside the zip, // but how can I had text content to that file...
// Could someone help me adding my sessionscope.htmlCode into the htmlfile.html. Thx
 
var entry:java.util.zip.ZipEntry = new java.util.zip.ZipEntry(htmlfile.html);
zipOutStream.putNextEntry(entry);
zipOutStream.write(sessionscope.htmlCode); // Write attachment into Zip 
 
 
downloadDocument.recycle();
zipOutStream.flush();
zipOutStream.close();
outStream.flush();
outStream.close();
facesContext.responseComplete();
 
I'm able to create a zip file containing all my attachment and to create my html file but I'm missing the content into my html file.

Thx in advance, 
 
Chris 
Dec 19, 2012, 7:25 PM
35 Posts
Re: Add text var into zipoutstream file
 Hi Forum,
 
Nobody has an idea to help me / can point me in the right direction? 
 
Thanks in advance, 
 
Chris 
Dec 19, 2012, 7:26 PM
35 Posts
Re: Add text var into zipoutstream file

Dec 19, 2012, 7:27 PM
35 Posts
Re: Add text var into zipoutstream file

Dec 26, 2012, 7:00 PM
35 Posts
Re: Add text var into zipoutstream file
Hi Forum, 
 
In the meantime I found the solution, really easy when you know ! 
 
 
var entry:java.util.zip.ZipEntry = new java.util.zip.ZipEntry(sessionScope.fileName);
zipOutStream.putNextEntry(entry);
zipOutStream.write(sessionScope.htmlCode.getBytes());
 
Thanks
 
Season's Greetings !
 
Chris 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal